<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket Client</title>
</head>
<body>
<script>
    // 创建一个新的WebSocket连接
    let socket = new WebSocket("ws://172.27.160.1:8080/ws");

    // 连接成功时的回调函数
    socket.onopen = function(e) {
        console.log("[open] Connection established");
    };

    // 接收到消息时的回调函数
    socket.onmessage = function(event) {
        console.log(`[message] Data received from server: ${event.data}`);
    };

    // 连接关闭时的回调函数
    socket.onclose = function(event) {
        if (event.wasClean) {
            console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
        } else {
            console.log('[close] Connection died');
        }
    };

    // 发生错误时的回调函数
    socket.onerror = function(error) {
        console.log(`[error] ${error.message}`);
    };
</script>
</body>
</html>
